{extend name="addon/supply/supply/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}
<div  class="layui-form">
	<div class="layui-form-item">
		<label class="layui-form-label">主营行业：</label>
		<div class="layui-input-inline">
			<p class="ns-input-text ns-len-mid">{$data.category_name}</p>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">供货商名称：</label>
		<div class="layui-input-inline">
			<p class="ns-input-text ns-len-mid">{$data.title}</p>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label img-upload-lable">供货商logo：</label>
		<div class="layui-input-block">
			<div class="upload-img-block img-upload">
				<div class="upload-img-box {notempty name="$data['logo']"}hover{/notempty}">
					<div class="ns-upload-default" id="logoUpload">
						{if condition="$data.logo"}
						<div id="preview_logoUpload" class="preview_img">
							<img layer-src src="{:img($data.logo)}" class="img_prev"/>
						</div>
						{else/}
						<div class="upload">
							<img src="SUPPLY_IMG/upload_img.png"/>
							<p>点击上传</p>
						</div>
						{/if}
					</div>
					<div class="operation">
						<div>
							<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
							<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
						</div>
						<div class="replace_img js-replace">点击替换</div>
					</div>
					<input type="hidden" name="logo" value="{$data.logo}">
				</div>
			</div>
		</div>
		<div class="ns-word-aux">
			<p>建议图片尺寸：200*60像素；图片格式：jpg、png、jpeg。</p>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">供货商简介：</label>
		<div class="layui-input-block">
			<textarea name="desc" class="layui-textarea ns-len-long">{$data.desc}</textarea>
		</div>
	</div>

	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
	</div>
</div>
{/block}
{block name="script"}
<script>
	layui.use(['form'], function(){
		var form = layui.form,
			repeat_flag = false; //防重复标识
			
		form.render();
			
		form.on('submit(save)', function(data){
			if (repeat_flag) return;
			repeat_flag = true;
			
			//删除图片
			if(!data.field.logo) logo_upload.delete();
			
			$.ajax({
				type: 'POST',
				url: ns.url("supply://supply/supply/config"),
				data: data.field,
				dataType: 'JSON',
				success: function(res) {
					layer.msg(res.message);
					repeat_flag = false;
					if (res.code == 0) {
						location.reload();
					}
				}
			});
		});

		// 供货商LOGO
		var logo_upload = new Upload({
			elem: '#logoUpload',
			url: ns.url("supply://supply/upload/image"),
		});
	});
</script>
{/block}
